<?php
class Db_GroupCategory extends MVC_SQL {
	public function __construct(){
		$this->setTable('ams_group_category_statictis');
	}
	
	public function getListGroupCategory($oModel)
	{
		$sSql="SELECT * FROM ams_group_category_statictis WHERE 1 ORDER BY group_name";
		return $this->getRecordsetExtend($sSql);
	}
	
	public function doUpdateCategory($aData){
		return $this->doUpdateByPK($aData);
	}
	
	public function getListSearchCategory($oModel)
	{
		$searck_key=$oModel->getData('search_key');
		$searck_key=trim($searck_key);
		$sWhere=" WHERE 1 ";
		if(is_numeric($searck_key))
		{
			$sWhere.=" AND product_category_yahoo_id = {$searck_key} ";
		}
		else
		{
			$sWhere.=" AND product_category_name like '%{$searck_key}%' ";
		}
		$sSql="SELECT * FROM ams_product_category ".$sWhere;
		//echo $sSql;
		
		return $this->getRecordsetExtend($sSql);
	}
	
	public function getListGroupChild($parent_id)
	{
		$sSql=" SELECT rt. * , r . *
				FROM ams_product_category rt
				INNER JOIN ams_group_category_statictis r ON ( 0
				OR r.group_child
				REGEXP CONCAT( '', '^', rt.product_category_id, '$' )
				OR r.group_child
				REGEXP CONCAT( '', '^', rt.product_category_id, ' ' )
				OR r.group_child
				REGEXP CONCAT( '', ' ', rt.product_category_id, ' ' )
				OR r.group_child
				REGEXP CONCAT( '', ' ', rt.product_category_id, '$' ) )
				WHERE r.group_id ={$parent_id}";
		return $this->getRecordsetExtend($sSql);
	}
	
	
}